package org.zetaframework.core.helper;

import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.stereotype.Component;

import static org.zetaframework.core.constants.Constants.*;

/**
 * <p>环境帮助类</p>
 *
 * 说明：<br>
 * 为什么叫Helper类，因为util类应该是只具有静态方法的类，不需要new出来也无需注入bean。所以用Helper命名比较好
 *
 * @author gcc
 */
@Component
public class EnvHelper {

    private final Environment environment;
    public EnvHelper(Environment environment) {
        this.environment = environment;
    }

    /**
     * 判断是否为开发环境
     */
    public boolean isDevEnvironment() {
        return environment.acceptsProfiles(Profiles.of(ENV_DEV));
    }

    /**
     * 判断是否为测试环境
     */
    public boolean isTestEnvironment() {
        return environment.acceptsProfiles(Profiles.of(ENV_TEST));
    }

    /**
     * 判断是否为生产环境
     */
    public boolean isProdEnvironment() {
        return environment.acceptsProfiles(Profiles.of(ENV_PROD));
    }

    /**
     * 获取当前激活的环境
     */
    public String[] getActiveProfiles() {
        return environment.getActiveProfiles();
    }

    /**
     * 检查是否包含指定环境
     */
    public boolean hasProfile(String profile) {
        return environment.acceptsProfiles(Profiles.of(profile));
    }


}
